package dd.server;

import java.util.Map;

import server.ClientState;
import server.IProtocolHandler;
import xml.Message;
import dd.model.Event;
import dd.model.serverModel;

/**
 * Server received the reportRequest and get the eventId which wants to generate the report
 */
public class AdminRetrieveAllEventsResponseController implements IProtocolHandler {

	@Override
	public Message process(ClientState state, Message request) {
		Map<String, Event> eventsMap = serverModel.getInstance().getEventIdEventMap();

		String xmlString = Message.responseHeader(request.id()) + "<eventsResponse>";

		for (String eventId : eventsMap.keySet()) {
			String event = "<event id='" + eventId + "' name='" + eventsMap.get(eventId).getEventName() + "' />";
			xmlString += event;
		}

		xmlString += "</eventsResponse></response>";

		return new Message(xmlString);
	}
}
